<?php
// +----------------------------------------------------------------------
// | Yzncms [ 御宅男工作室 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://yzncms.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | fastadmin: https://www.fastadmin.net/
// +----------------------------------------------------------------------

// +----------------------------------------------------------------------
// | 邮箱验证码接口
// +----------------------------------------------------------------------
namespace app\api\controller;

use app\admin\model\Staff;
use app\admin\model\UserModel;
use app\common\controller\Api;
use app\common\library\Ems as Emslib;
use app\common\model\Upload;
use app\member\model\Member;
use think\facade\Hook;
use think\facade\Validate;

/**
 * @title 邮箱验证码接口
 * @controller api\controller\Ems
 * @group base
 */
class User extends Api
{

    public function getStaffInfo()
    {
        $data = (new Staff())->getStaffInfo($this->request_array);
        $data['code'] == 200 ? $this->success($data['msg'], $data['data']) : $this->error($data['msg']);
    }


    public function updateAvatar(){
        $file = request()->file('file');
        $data = Upload::uploadImages($file);
        if($data['code'] == 201){
            $this->error($data['msg']);
        }
        $img = $data['data'][0];
        $user = Staff::get($this->request_array['uid']);
        if($user){
            $user->avatar = $img;
            if($user->save()){
                $this->success('修改成功',$user);
            }else{
                $this->error('修改失败，请重新尝试');
            }
        }else{
            $this->error('用户不存在');
        }
    }


    public function updatePassword()
    {
        $data = (new Staff())->updatePassword($this->request_array);
        $data['code'] == 200 ? $this->success($data['msg'], $data['data']) : $this->error($data['msg']);
    }


    public function loginOut(){
        $data = (new Staff())->loginOut($this->request_array);
        $data['code'] == 200 ? $this->success($data['msg'],$data['data']) : $this->error($data['msg']);
    }


}
